﻿using UnityEngine;
using System.Collections;

namespace UI
{

    public class UICopyAwardItem :MonoBehaviour
    {
        public string[] color_str = new string[3] 
        { 
            "UI_item_title_xing_green", 
            "UI_item_title_xing_blue", 
            "UI_item_title_xing_zi" 
        };

        public UILabel awardCondition;
        public GameObject dropItem;
        public UIGrid dropItemGrid;
        public UISprite star;
        public UILabel submitBtnTxt;
        
        string awardConditionTxt;
        public UICopyAwardEvent uiEvt;

        public GameObject getButton;
        public GameObject hasGetBtn;
        public GameObject hotCanGetBtn;

        public int seq=0;

        void Awake()
        {
            this.submitBtnTxt.text = TableTextBlo.GetText( "award_get" );
            this.awardConditionTxt = TableTextBlo.GetText( "copy_star_award" );
        }

        public void Init(int needStar,int seq,UIDropData dropData,UICopyAwardEvent evt,UICopyAward award)
        {
            this.awardCondition.text = string.Format( awardConditionTxt, needStar );
            this.star.spriteName = color_str[seq];
            this.seq=seq;
            this.uiEvt = evt;
            foreach (var kv in dropData.drop_dict)
            {
                var goodsId = kv.Key;
                var count = kv.Value;

                GameObject obj = GameObject.Instantiate( dropItem ) as GameObject;
                obj.SetActive( true );
                obj.transform.SetParent( dropItemGrid.transform );
                obj.transform.localScale = Vector3.one*0.85f;
                var item = obj.GetComponent<CommonIcon>();

                var drag = obj.AddComponent<UIDragScrollView>();
                drag.scrollView = award.bk.GetComponent<UIDragScrollView>().scrollView;
                

                item.SetData(goodsId, true, count);
            }
            dropItemGrid.Reposition();
        }

        public void OnClick()
        {
            uiEvt.OnGetBoxClick( seq );
        }
        

        public void SetCanNotGet()
        {
            getButton.SetActive(false);
            hotCanGetBtn.SetActive(false);
            hasGetBtn.SetActive(false);

            hotCanGetBtn.SetActive(true);
        }

        public void SetHasGet()
        {
            getButton.SetActive(false);
            hotCanGetBtn.SetActive(false);
            hasGetBtn.SetActive(false);

            hasGetBtn.SetActive(true);
        }

        public void SetCanGet()
        {
            getButton.SetActive(false);
            hotCanGetBtn.SetActive(false);
            hasGetBtn.SetActive(false);

            getButton.SetActive(true);
        }

        public TweenAlpha alpha;

    }
}